package com.educhains.web.util;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
import com.educhains.module.user.vo.User;
import com.educhains.module.user.vo.UserWallet;

import java.util.Map;

/**
 * @author YuRun
 * @since 2017年8月21日
 */
public class JsonUtils extends JSON {

    static {
        defaultSettings();
    }

    /**
     * Default setting
     */
    public static void defaultSettings() {
        JSON.DEFAULT_GENERATE_FEATURE |= SerializerFeature.DisableCircularReferenceDetect.getMask();
        JSON.DEFAULT_GENERATE_FEATURE |= SerializerFeature.WriteDateUseDateFormat.getMask();
    }

    /**
     * To JSON String
     *
     * @param bean
     * @param filterClass
     * @param includedProperties
     * @return
     */
    public static String toJSONString(Object bean, Class<?> filterClass, String... includedProperties) {
        SimplePropertyPreFilter filter = new SimplePropertyPreFilter(filterClass, includedProperties);
        return JSON.toJSONString(bean, filter, new SerializerFeature[0]);
    }

}
